import React, { useRef ,useState,useEffect} from 'react';
import { setContext } from '@redux-saga/core/effects';

function Example (){
    // 可以获取dom
  const inputEi = useRef(null)
  const onButtonClick=()=>{
    inputEi.current.value='jspang'
    console.log(inputEi)
  }
  const [text,setContext]=useState('pang')
//   也可以存储变量
 const testref = useRef()
 useEffect(()=>{
    testref.current=text;
    console.log(testref.current)
 })
  return(
      <>
      <input ref={inputEi} type='text'></input>
      <button onClick={onButtonClick}>在input显示文字</button>
      <br></br>
      <br></br>
      <input type='text' value ={text} onChange={(e)=>{setContext(e.target.value)}}></input>
      </>
  )
}

export default Example